<?php
$owner_id = $_SESSION['acc_id'];
//echo $owner_id;
?> 
<div class="row">
    <form action="#" method="post" name="frmlist">
        <div class="title"><h4><?php echo $lang['CARD_FIDELITY_TITLE']; ?></h4></div>            

        <table cellpadding="0" cellspacing="0" border="0" width="100%" class="table">
            <tr>
                <th width="5%" align="center">Id</th>
                <th width="15%" align="center">Screen name</th>
                <th width="15%" align="center">First name</th> 
                <th width="15%" align="center">Last name</th>
                <th width="17%" align="center">Mobile number</th>
                <th width="17%" align="center">Count number</th>
                <th width="17%" align="center">Actions</th>
            </tr>
        </table>

        <table cellpadding="0" cellspacing="0" border="0" width="100%" align="center" class="table table-striped table-hover">
            <?php
            $qstring = '';
            $rowsPerPage = isset($_GET['num']) ? $_GET['num'] : '10';
            $sql = "SELECT fc.*, u.*
                        FROM fidelity_card AS fc, tbluser AS u       
                        WHERE fc.user_id = u.id  
                        AND fc.owner = '" . $owner_id . "'
                        ORDER BY fc.fc_id ASC";
            $result = mysql_query(getPagingQuery($sql, $rowsPerPage));
            $pagingLink = getPagingLink($sql, $rowsPerPage, $qstring);
            $i = 1;
            $n = 0;
            $page = (!empty($_GET['page'])) ? $_GET['page']: '0';
            $nomlist = (!empty($page)) ? $rowsPerPage * $page - 10 : '0';
            while ($row = mysql_fetch_assoc($result)) {
                $n++;
                extract($row);
                if ($i % 2) {
                    $class = 'row1';
                } else {
                    $class = 'row2';
                }
                ?>
                <tr class="<?php echo $class; ?>">              
                    <td class="p_l" width="5%" align="center"><?php echo $n + $nomlist?></td>
                    <td class="p_l" width="15%" align="center"><?php echo $row['username'] ?></td>
                    <td class="p_l" width="15%" align="center"><?php echo $row['first_name'] ?></td>
                    <td class="p_l" width="15%" align="center"><?php echo $row['last_name'] ?></td> 
                    <td class="p_l" width="17%" align="center"><?php echo $row['mobile'] ?></td>
                    <td class="p_l" width="17%" align="center"><?php echo $row['count_number'] ?></td> 
                    <td class="p_l" width="17%" align="center"><div class="btn-group">       
                            <a title="delete" onclick="return confirm('Are you sure you want to delete?')" class="btn btn-primary btn btn-danger" href="index.php?view=delete_fidelity&id=<?php echo $row['fc_id'] ?>"><i class="icon-trash icon-white"></i></a>


                </tr>
                <?php
                $i++;
            } //end while
            ?>   

        </table>
        <div class="row-fluid">
            <div class="span7">
                <div class="wp-pagenavi">
                    <?php echo $pagingLink; ?>
                    <div class="clear"></div>
                </div>
            </div>
            <div class="span3 offset2">
                view per page
                <select class="right span4" name="numpage" onchange="javascript:viewByNumPage();">
                    <option value="10" <?php echo($rowsPerPage == 10) ? ' selected="selected"' : ''; ?>>10</option>
                    <option value="20" <?php echo($rowsPerPage == 20) ? ' selected="selected"' : ''; ?>>20</option>
                    <option value="30" <?php echo($rowsPerPage == 30) ? ' selected="selected"' : ''; ?>>30</option>
                    <option value="40" <?php echo($rowsPerPage == 40) ? ' selected="selected"' : ''; ?>>40</option>
                    <option value="50" <?php echo($rowsPerPage == 50) ? ' selected="selected"' : ''; ?>>50</option>        
                </select>
            </div>            
        </div> 

    </form>
</div>
